<template>
  <el-card style="margin-bottom:20px;">
    <div slot="header" class="clearfix">
      <span>个人信息</span>
    </div>

    <div class="user-profile">
      <div class="box-center" @mouseover="hovering = true" @mouseout="hovering = false" @click="imagecropperShow=true">
        <el-avatar :src="user.avatar" style="width: 100px;height: 100px" />
        <div v-show="hovering" class="avatar-model">
          <span style="color: white">更换头像</span>
        </div>
      </div>
      <div class="box-center">
        <div class="user-name text-center">{{ user.name }}</div>
        <div class="user-role text-center text-muted"><span v-for="(item, index) in user.roles" :key="index">{{ item.role | uppercaseFirst }}</span></div>
      </div>
    </div>

    <div class="user-bio">
      <div class="user-education user-bio-section">
        <div class="user-bio-section-header"><svg-icon icon-class="education" /><span>个人介绍</span></div>
        <div class="user-bio-section-body">
          <div class="text-muted">
            觉醒年代》告诉我们在那个时代有这样一群年轻人为了救国在披荆斩棘地探索中国的出路。周老师的这一讲非常硬核，带我们仔细剖析了20世纪初我们的革命先辈从思想引领革命到务实社会改造的曲折转变，需要同学们静下心来慢慢体悟哦。
            <br><br>----个人介绍模块，以后有时间开发----
          </div>
        </div>
      </div>

      <image-cropper
        v-show="imagecropperShow"
        :key="imagecropperKey"
        :width="300"
        :height="300"
        url="http://localhost:8090/"
        :headers="{authorization:'+ $store.getters.token +'}"
        lang-type="zh"
        @close="close"
        @crop-upload-success="cropSuccess"
      />
    </div>
  </el-card>
</template>

<script>
import ImageCropper from '@/components/ImageCropper'
import PanThumb from '@/components/PanThumb'
import { updateAvatar } from '@/api/user'
export default {
  components: { ImageCropper, PanThumb },
  props: {
    user: {
      type: Object,
      default: () => {
        return {
          name: '',
          email: '',
          avatar: '',
          role: ''
        }
      }
    }
  },
  data() {
    return {
      hovering: false,
      imagecropperShow: false,
      imagecropperKey: 0,
      image: 'https://wpimg.wallstcn.com/577965b9-bb9e-4e02-9f0c-095b41417191'
    }
  },
  methods: {
    uploadAvatar() {

    },
    cropSuccess(resData) {
      console.log(resData)
      this.imagecropperShow = false
      this.imagecropperKey = this.imagecropperKey + 1
      this.image = resData
      updateAvatar({ id: this.$store.getters.id, avatar: resData }).then(
        res => {
          if (res.status === 200) {
            window.location.reload()
            this.$message({
              message: '更换头像成功',
              duration: 800,
              type: 'success'
            })
          }
        }
      )
    },
    close() {
      this.imagecropperShow = false
    }
  }
}
</script>

<style lang="scss" scoped>
.box-center {
  margin: 0 auto;
  display: table;
}
.avatar-model {
  position: absolute;
  top: 87px;
  z-index: 99;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  opacity:80%;
  background-color: rgba(83, 93, 102, 0.9);
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
}

.text-muted {
  color: #777;
}

.user-profile {
  .user-name {
    font-weight: bold;
  }

  .box-center {
    padding-top: 10px;
  }

  .user-role {
    padding-top: 10px;
    font-weight: 400;
    font-size: 14px;
  }

  .box-social {
    padding-top: 30px;

    .el-table {
      border-top: 1px solid #dfe6ec;
    }
  }

  .user-follow {
    padding-top: 20px;
  }
}

.user-bio {
  margin-top: 20px;
  color: #606266;

  span {
    padding-left: 4px;
  }

  .user-bio-section {
    font-size: 14px;
    padding: 15px 0;

    .user-bio-section-header {
      border-bottom: 1px solid #dfe6ec;
      padding-bottom: 10px;
      margin-bottom: 10px;
      font-weight: bold;
    }
  }
}
</style>
